﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

//[InitializeOnLoad]
public class FpsDisplay : UILogBehaviour
{
    private float m_LastUpdateShowTime=0f;  //上一次更新帧率的时间;  
    private float m_UpdateShowDeltaTime=1f;//更新帧率的时间间隔;  
    private int m_FrameUpdate=0;//帧数;  
    private float m_FPS=0;  
	private float calDrawTime;
	private int drawCallNum;
    private string versionInfo;
	private string texInfo = "";

    void Start ()   
    {  
        m_LastUpdateShowTime=Time.realtimeSinceStartup;  
    }
	
    void Update ()   
    {  
        Application.targetFrameRate = 60;

		m_FrameUpdate++;
        if(Time.realtimeSinceStartup-m_LastUpdateShowTime>=m_UpdateShowDeltaTime)  
        {  
            m_FPS=m_FrameUpdate/(Time.realtimeSinceStartup-m_LastUpdateShowTime);  
            m_FrameUpdate=0;  
            m_LastUpdateShowTime=Time.realtimeSinceStartup;  
        }
    }  
    
//    private CommonUtil.GUILabelCache cache = null;
    protected  override void myOnGUI()  
    {
//        string info = string.Format("F:{0:00}", m_FPS);
//        info += versionInfo;
//        if (cache == null || Application.isEditor || cache.str.Length != info.Length)
//        {
//            CommonUtil.Label(info, 22, LabelPos.L | LabelPos.B);
//        }
//        else
//        {
//            cache.str = info;
//            cache.draw();
//        }

        string info = string.Format("F:{0:00}", m_FPS);
        info += versionInfo;
        GuiUtil.Label(info, 22, LabelPos.L | LabelPos.B);

    }  

}
